﻿function callClientFunction ( client, funcname, ... )
    local arg = { ... }
    if ( arg [ 1 ] ) then
        for key, value in next, arg do
            if ( type ( value ) == "number" ) then arg [ key ] = tostring ( value ) end
        end
    end
    -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element
    triggerClientEvent ( client, "onServerCallsClientFunction", resourceRoot, funcname, unpack ( arg or {} ) )
end

function dataCleaner ()
	if getElementType ( source ) == "vehicle" then
		removeElementData ( source, "VCSM" )
		for k, v in pairs ( getVehicleOccupants ( source ) ) do
			setTimer ( callClientFunction, 50, 1, v, "g_GridUpdate" )
		end
	end
end
addEventHandler ( "onElementModelChange", root, dataCleaner )
addEventHandler ( "onElementDestroy", root, dataCleaner )
addEventHandler ( "onVehicleExplode", root, dataCleaner )